function ccR_Shaman_Totem_Exists(name)
	local iDescriptor = ccRS.DeathKnight_RisenAllyDescriptor
	if iDescriptor == nil then iDescriptor = "0x48" end
	for i = 0, # ccrObjectListTable do
		local obj = ccrObjectListTable[i]
		if obj ~= nil
		and obj:Exists()
		and obj:GetName() == name
		and obj:GetInt64Descriptor(iDescriptor) == Player:GetGUID()
		then
			-- Found it
			return true
		end
	end
	-- Not found
	return false
end
function ccR_Shaman_Totem_Distance(name, unit)
	if ccR_Shaman_Totem_Exists(name) then
		local iDescriptor = ccRS.DeathKnight_RisenAllyDescriptor
		if iDescriptor == nil then iDescriptor = "0x48" end
		for i = 0, # ccrObjectListTable do
			local obj = ccrObjectListTable[i]
			if obj ~= nil
			and obj:Exists()
			and obj:GetName() == name
			and obj:GetInt64Descriptor(iDescriptor) == Player:GetGUID()
			then
				-- Found it
				return obj:GetDistance(unit)
			end
		end
	else
		return nil
	end
end

vLast_Keep_Fire_Totems_In_Range_Check = 0.1
function ccR_Shaman_Keep_Fire_Totems_In_Range()
	if ccrValidTarget()
	and ccrPlayerIsInCombat()
	and (GetTime()-vLast_Keep_Fire_Totems_In_Range_Check) >= 3
	then
		local vCount = ccrTargetCount(10)
		if vCount == 1 or not ccrPlayerHasSpell(MAGMA_TOTEM) then
			local vTotemDistance = ccR_Shaman_Totem_Distance("Searing Totem", Target)

			if vTotemDistance ~= nil
			and vTotemDistance >= 25
			and ccrSpellIsReady(SEARING_TOTEM)
			then
				ccrCast(SEARING_TOTEM)
				vLast_Keep_Fire_Totems_In_Range_Check = GetTime()
				return
			end

			if vTotemDistance == nil
			and Player:GetDistance(Target) <= 25
			and ccrSpellIsReady(SEARING_TOTEM)
			then
				ccrCast(SEARING_TOTEM)
				vLast_Keep_Fire_Totems_In_Range_Check = GetTime()
				return
			end

			return
		end
		if vCount >= 2
		and ccrPlayerHasSpell(MAGMA_TOTEM)
		then
			local vTotemDistance = ccR_Shaman_Totem_Distance("Magma Totem", Target)

			if vTotemDistance ~= nil
			and vTotemDistance >= 8
			and ccrSpellIsReady(MAGMA_TOTEM)
			then
				ccrCast(MAGMA_TOTEM)
				vLast_Keep_Fire_Totems_In_Range_Check = GetTime()
			end

			if vTotemDistance == nil
			and Player:GetDistance(Target) <= 8
			and ccrSpellIsReady(MAGMA_TOTEM)
			then
				ccrCast(MAGMA_TOTEM)
				vLast_Keep_Fire_Totems_In_Range_Check = GetTime()
			end

			return
		end
	end
end